<?php

namespace App\Models\User;
use App\Models\Member;

use Illuminate\Database\Eloquent\Model;

class Account extends Model
{
    protected $table = 'jxt_user_account';

    public $primaryKey = 'account_id';

    public $timestamps = false;

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    public function getUser()
    {
        /*return $this->select(['jxt_user_account.*','a.username','a.telephone','a.initial_role_id'])
            ->rightJoin('jxt_xp_user as a','a.id','jxt_user_account.user_id');*/

        return $this->select(['jxt_user_account.*','a.username','a.telephone','a.initial_role_id'])
            ->rightJoin('jxt_xp_user as a','a.id','jxt_user_account.user_id');
    }

    public function vip()
    {
        return $this->belongsToMany(Member\Price::class, 'jxt_member_user','user_id','vip_id')
            ->where('expiry_time', '>', time())
            ->select(['user_id','vip_id','name'])
            ->orderBy('jxt_member_price.lv','DESC');
    }






}
